package logic

import (
	"context"

	"go-zero-mall/app/admin/cmd/rpc/internal/svc"
	"go-zero-mall/app/admin/cmd/rpc/pd"
	"go-zero-mall/app/admin/model"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type RoleListMenuLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRoleListMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleListMenuLogic {
	return &RoleListMenuLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 角色-菜单
func (l *RoleListMenuLogic) RoleListMenu(in *pd.UmsRoleListMenuReq) (*pd.UmsRoleListMenuResp, error) {
	d, err := l.svcCtx.UmsRoleMenuRelationModel.FindOne(l.ctx, in.Id)
	if err != nil && err != model.ErrNotFound {
		return nil, err
	}
	var r pd.UmsRoleListMenuResp

	copier.Copy(&r, d)
	return &r, nil
}
